import { mainRoutes } from "../router";

//分类数据整合为tree
export const dataToTree = (data) => {
  let parentList = data.filter((item) => item.parentId == "0-0");
  parentList.forEach((item) => {
    let children = data.filter((child) => item.objectId == child.parentId);
    if (children.length) {
      item.children = children;
    }
  });
  return parentList;
};

// 将路由数据包处理为， {'/category':'分类管理'}

export const routeMapTool = (arr) => {
  let routeMap = {};
  function loop(routes) {
    routes.forEach((item) => {
      if (item.children) {
        loop(item.children);
      }
      routeMap[item.key] = item.label;
    });
  }
  loop(arr);
  return routeMap;
};
